#!/usr/bin/php -c/etc/gtk/php.ini
<?php

define('EXECROOT',dirname(__FILE__));

class bobSound extends OpenALSource {

	public function __construct() {
		parent::__construct();

		if(file_exists($file = EXECROOT.'/commopen.wav')) {
			$this->buffer = OpenALBuffer::newFromFile($file);
		} else {
			fputs(STDERR,"unable to open {$file}.\n");
			exit(0);
		}		
	
		return;
	}
	
	public function destroy() {
		$this->free();
		return;
	}

}

class bobWindow extends GtkWindow {

	public function __construct() {
		parent::__construct();

		$this->vbox = new GtkVBox;
		$this->hbox = new GtkHBox;
		$this->button = new GtkButton('Click!');
		$this->sound = new bobSound;
		print_r($this->sound);		
		
		$this->set_title('PHP-GTK Plus OpenAL');
		$this->set_position(Gtk::WIN_POS_CENTER);
		$this->set_size_request(300,250);
		$this->connect_simple('delete-event',array($this,'on_quit'));
		
		$this->button->child->set_padding(24,12);
		$this->button->connect_simple('clicked',array($this,'on_click'));
		
		$this->hbox->pack_start($this->button,true,false,0);
		$this->vbox->pack_start($this->hbox,true,false,0);
		$this->add($this->vbox);
		
		$this->show_all();		
		return;
	}
	
	public function on_click() {
		$this->sound->play();
		return;
	}
	
	public function on_quit() {
		$this->hide();
		$this->sound->destroy();
		
		Gtk::main_quit();
		return;
	}

}

$w = new bobWindow;

Gtk::main();

$w->destroy();

exit(0);

?>